package service;

import common.util.PageBean;
import mapper.RegisterInfoList;
import model.dto.RegistryDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @className: service.RegisterInfoListServiceImpl
 * @author: Xia
 * @create: 2023-03-18 11:17
 */
@Service
public class RegisterInfoListServiceImpl implements RegisterInfoListService {
    @Autowired
    private RegisterInfoList registerInfoList;
    @Override
    public PageBean<RegistryDto> page(String patientIdCard, String doctorName, Integer status, Integer index) {
        PageBean<RegistryDto> bean = new PageBean<>();
        //            1.获取数据总条数
        Integer count = registerInfoList.count();
        bean.setTotal(count);
//            2.获取总页数
        Integer totalPage = count % bean.pageSize == 0 ? count / bean.pageSize : count / bean.pageSize+1;
//            3.判断如果首页数大于总页数的话，首页数=总页数；
        if(index>totalPage){
            index=totalPage;
        }
//            4.判断如果首页数小于1的话，首页数=1
        if(index<1){
            index=1;
        }
        Integer start = (index-1)*bean.pageSize;
        List<RegistryDto> users = registerInfoList.getRegisterInfoList(patientIdCard,doctorName,status,start,bean.pageSize);
        bean.setPages(totalPage);
        bean.setData(users);
        bean.setPageNo(index);
        return bean;
    }
}
